//
//  UIWindow+Extension.m
//  黑马微博2期
//
//  Created by apple on 14-10-12.
//  Copyright (c) 2014年 heima. All rights reserved.
//


#import <FLEXManager.h>
#import "UIWindow+Extension.h"
#import "HWNewfeatureViewController.h"
#import "ZBTabbarViewController.h"

@implementation UIWindow (Extension)
- (void)switchRootViewController
{
    NSString *key = @"CFBundleVersion";
    // 上一次的使用版本（存储在沙盒中的版本号）
    NSString *lastVersion = [[NSUserDefaults standardUserDefaults] objectForKey:key];
    // 当前软件的版本号（从Info.plist中获得）
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
    
    if ([currentVersion isEqualToString:lastVersion]) { // 版本号相同：这次打开和上次打开的是同一个版本
        self.rootViewController = [[ZBTabbarViewController alloc] init];
    } else { // 这次打开的版本和上一次不一样，显示新特性
        self.rootViewController = [[HWNewfeatureViewController alloc] init];
        NSString *currentVersion = [NSBundle mainBundle].infoDictionary[key];
        // 将当前的版本号存进沙盒
        [[NSUserDefaults standardUserDefaults] setObject:currentVersion forKey:key];
        [[NSUserDefaults standardUserDefaults] synchronize];
        
    }
    
}

//默认是NO，所以得重写此方法，设成YES
- (BOOL)canBecomeFirstResponder {
     return YES;
}

 
- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
    [[FLEXManager sharedManager] showExplorer];
}
 

- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event
{

}
 
- (void)motionCancelled:(UIEventSubtype)motion withEvent:(UIEvent *)event
{
}



@end
